import javax.swing.tree.TreeNode;
import java.util.LinkedList;
import java.util.Queue;

public class code {
/*
判断一棵树是不是完全二叉树
*/
    public boolean isCompleteTree(TreeNode root) {
        if (root==null) return true; //空树
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while(!queue.isEmpty()) {
            TreeNode cur = queue.poll();
            if(cur != null) {
                queue.offer(cur.left);//虽然能放null，但cur不能为空
                queue.offer(cur.right);
            } else {
                break;
            }
        }
        //看有没有null
        while(!queue.isEmpty()){
            if(queue.poll()!=null) {
                return false;
            }
        }
        return true;
    }
}
